﻿namespace K9Nano.Captcha;

public interface ICaptchaManager
{
    /// <summary>
    /// 创建验证码图片
    /// </summary>
    /// <param name="requestId">请求ID</param>
    /// <param name="expire">有效期</param>
    /// <param name="length">验证码长度</param>
    /// <returns>验证码及验证码图片</returns>
    CaptchaInfo GenerateImage(string requestId, TimeSpan expire, int length = 4);

    /// <summary>
    /// 创建验证码图片
    /// </summary>
    /// <param name="requestId">请求ID</param>
    /// <param name="expire">有效期</param>
    /// <param name="length">验证码长度</param>
    /// <returns>验证码</returns>
    string GenerateCode(string requestId, TimeSpan expire, int length);

    /// <summary>
    /// 验证验证码
    /// </summary>
    /// <param name="requestId">请求ID</param>
    /// <param name="code">验证码</param>
    /// <returns></returns>
    bool Validate(string requestId, string code);
}

public record CaptchaInfo(string Code, byte[] Png);